package com.xxwu.springblogsystem.model;

import com.xxwu.springblogsystem.Contants;
import lombok.Data;
import org.springframework.stereotype.Component;

@Component
@Data
public class Result {
    private int code;
    private String errMsg;
    private Object data;
    public static Result success(Object data) {
        Result result = new Result();
        result.setCode(Contants.SUCCESS_CODE);
        result.setData(data);
        result.setErrMsg("");
        return result;
    }
    public static Result fail(String errMsg) {
        Result result = new Result();
        result.setCode(Contants.FAIL_CODE);
        result.setData("");
        result.setErrMsg(errMsg);
        return result;
    }
    public static Result fail(String errMsg, Object data) {
        Result result = new Result();
        result.setCode(Contants.FAIL_CODE);
        result.setData(data);
        result.setErrMsg(errMsg);
        return result;
    }
    public static Result unlogin() {
        Result result = new Result();
        result.setCode(Contants.UNLOGIN_CODE);
        result.setData("");
        result.setErrMsg("用户未登陆");
        return result;
    }
}
